package cn.fan.emq.core;


import cn.fan.emq.config.EmqClient;
import lombok.extern.slf4j.Slf4j;
import org.eclipse.paho.client.mqttv3.MqttException;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;

import javax.annotation.PostConstruct;

/**
 * 订阅主题就会主动推送
 */
@Component
@Slf4j
public class Monitor {

    @Autowired
    private EmqClient emqClient;

//    @Autowired
//    private QuotaService quotaService;


    @PostConstruct
    public void init() {
        System.out.println("初始化方法，订阅主题");
        emqClient.connect();
//
//        quotaService.getAllSubject().forEach(s -> {
//            //共享订阅模式(集群时只会有一个收到)
//            try {
//                emqClient.subscribe("$queue/" + s);
//            } catch (MqttException e) {
//                e.printStackTrace();
//            }
//        });

    }

}
